//
//  DropOneViewController.m
//  YYPopMenuView
//
//  Created by 蓓蕾 on 2021/8/26.
//

#import "DropOneViewController.h"
#import "GHDropMenu.h"

@interface DropOneViewController ()<GHDropMenuDelegate>
@property (nonatomic , strong) GHDropMenu *dropMenu;

@end

@implementation DropOneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createDropMenu];
}

-(void)createDropMenu
{
    
    NSArray *titles = @[@"智能排序",@"价格",@"品牌",@"筛选"];
    NSArray *data1 = @[@"价格从高到低",@"价格从低到高"];
    NSMutableArray *dataArray1 = [NSMutableArray array];
    for (NSInteger index = 0 ; index < data1.count; index++) {
        GHDropMenuModel *dropMenuModel = [[GHDropMenuModel alloc]init];
        dropMenuModel.title = data1[index];
        [dataArray1 addObject:dropMenuModel];
    }
    
    NSArray *data2 = @[@"0 - 10 元",@"10-20 元",@"20-50 元",@"50-100 元",@"100 - 1000元"];
    NSMutableArray *dataArray2 = [NSMutableArray array];
    for (NSInteger index = 0 ; index < data2.count; index++) {
        GHDropMenuModel *dropMenuModel = [[GHDropMenuModel alloc]init];
        dropMenuModel.title = data2[index];
        [dataArray2 addObject:dropMenuModel];
    }
    
    NSArray *data3 = @[@"psp",@"psv",@"nswitch"];
    NSMutableArray *dataArray3 = [NSMutableArray array];
    for (NSInteger index = 0 ; index < data3.count; index++) {
        GHDropMenuModel *dropMenuModel = [[GHDropMenuModel alloc]init];
        dropMenuModel.title = data3[index];
        [dataArray3 addObject:dropMenuModel];
    }
  
    NSArray *data4 = @[@"上午",@"下午",@"早上",@"晚上"];
    NSMutableArray *dataArray4 = [NSMutableArray array];
    for (NSInteger index = 0 ; index < data4.count; index++) {
        GHDropMenuModel *dropMenuModel = [[GHDropMenuModel alloc]init];
        dropMenuModel.tagName = data4[index];
        [dataArray4 addObject:dropMenuModel];
    }
    
    NSArray *data5 = @[@"呵呵",@"哈哈",@"嘿嘿",@"呵呵",@"哈哈",@"嘿嘿"];
    NSMutableArray *dataArray5 = [NSMutableArray array];
    for (NSInteger index = 0 ; index < data5.count; index++) {
        GHDropMenuModel *dropMenuModel = [[GHDropMenuModel alloc]init];
        dropMenuModel.tagName = data5[index];
        [dataArray5 addObject:dropMenuModel];
    }
    
    NSArray *data6 = @[@"呵呵11"];
    NSMutableArray *dataArray6 = [NSMutableArray array];
    for (NSInteger index = 0 ; index < data6.count; index++) {
        GHDropMenuModel *dropMenuModel = [[GHDropMenuModel alloc]init];
//        dropMenuModel.tagName = data6[index];
        [dataArray6 addObject:dropMenuModel];
    }
    NSArray *sectionHeaderTitles = @[@"单选",@"多选",@"价格"];
    NSMutableArray *sections = [NSMutableArray array];
    
    for (NSInteger index = 0; index < sectionHeaderTitles.count; index++) {
        GHDropMenuModel *dropMenuModel = [[GHDropMenuModel alloc]init];
        dropMenuModel.sectionHeaderTitle = sectionHeaderTitles[index];

        if (index == 0) {
            dropMenuModel.dataArray = dataArray4;
            dropMenuModel.isMultiple = NO;
            dropMenuModel.filterCellType = GHDropMenuFilterCellTypeTag;
        } else if (index == 1) {
            dropMenuModel.dataArray = dataArray5;
            dropMenuModel.isMultiple = YES;
            dropMenuModel.filterCellType = GHDropMenuFilterCellTypeTag;

        } else if (index == 2) {
            dropMenuModel.filterCellType = GHDropMenuFilterCellTypeInput;
            dropMenuModel.dataArray = dataArray6;
        } else {
            
        }
        [sections addObject:dropMenuModel];
    }
    NSMutableArray *titlesArray = [NSMutableArray array];
    NSArray *types = @[
                       @(GHDropMenuTypeTitle),
                       @(GHDropMenuTypeTitle),
                       @(GHDropMenuTypeTitle),
                       @(GHDropMenuTypeFilter),
                       ];
    
    for (NSInteger index = 0 ; index < titles.count; index++) {
        GHDropMenuModel *dropMenuModel = [[GHDropMenuModel alloc]init];
        dropMenuModel.title = titles[index];
        NSNumber *typeNum = types[index];
        dropMenuModel.dropMenuType = typeNum.integerValue;
        if (index == 0) {
            dropMenuModel.dataArray = dataArray1;
        } else if (index == 1) {
            dropMenuModel.dataArray = dataArray2;
        } else if (index == 2) {
            dropMenuModel.dataArray = dataArray3;
        } else if (index == 3) {
            dropMenuModel.dataArray = dataArray4;
            dropMenuModel.sections = sections;
        }
        dropMenuModel.identifier = index;
        [titlesArray addObject:dropMenuModel];
    }
    
    GHDropMenuModel *dropMenuModel = [[GHDropMenuModel alloc]init];
    dropMenuModel.frame = CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 44);
    dropMenuModel.titles = titlesArray.mutableCopy;
    dropMenuModel.menuHeight = 60;

    GHDropMenu *dropMenu = [[GHDropMenu alloc]creatDropMenuWithConfiguration:dropMenuModel];
    dropMenu.delegate = self;
    self.dropMenu = dropMenu;
    [self.view addSubview:self.dropMenu];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
